home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / ansi / grabasc.zip / GRABASC.C < prev    next >
Text File  |  1992-03-21  |  3KB  |  96 lines

  1. /*
  2.    grabasc.c by Bill Buckels January 25, 1992
  3.  
  4.    An trivial tsr ascii screen capture utility
  5.    for 80-column text mode 3 or 7 written in MIX POWER C
  6.  
  7.    grab the print screen key and save ascii to disk
  8.  
  9.    compile and link with a 2K stack and a 2K heap using the
  10.    following sequence...
  11.  
  12.    pc grabasc.c
  13.    pcl [2K,2K] grabasc.mix
  14.  
  15.    In case anyone thinks that this code is something special...
  16.    It ain't and is hereby by placed by me into the public domain
  17.    where it can be used and copied freely.
  18.  
  19.    This TSR has been used safely by me and works well on a clean
  20.    system. Reboot after use as with any screen capture utility.
  21.  
  22.    I will not be held responsible for self-inflicted wounds.
  23.  
  24. */
  25.  
  26. #include <bios.h>
  27. #include <stdio.h>
  28. #include <dos.h>
  29.  
  30. unsigned SCREENSEG = 0xb800; /* default to the CGA */
  31.                              /* adjust for people with mono */
  32.  
  33. /* the current video mode */
  34. /* we don't want to grab squinty modes or graphics */
  35. char far *vmodeptr = (char far *)(unsigned long)0x0400049;
  36.  
  37. void interrupt grabasc(void)
  38. {
  39.  
  40.     FILE *fp;
  41.     static char far *crtptr;
  42.     unsigned char temp;
  43.     unsigned row,col,target;
  44.  
  45.     char *filename="HANDFULL.TXT";
  46.  
  47.     disable();
  48.  
  49.     /* make sure we are in a legal text mode */
  50.     temp=vmodeptr[0];
  51.     if(temp == 2|| temp ==3 || temp==7)
  52.     {
  53.       /* open HANDFULL.TXT for append and write screen bytes  */
  54.       /* without attributes. put a carriage return- line feed */
  55.       /* at the end of each row... */
  56.  
  57.       fp=fopen(filename,"ab");
  58.       for(row=0;row<25;row++)
  59.         {
  60.         /* point to the start of each line of text */
  61.         crtptr=MK_FP(SCREENSEG,row*160);
  62.  
  63.         /* skip the attributes and save the ascii to disk */
  64.         /* trim the white space while we are at it...     */
  65.         /* we need to check first then write...           */
  66.         for(col=0;col<160;col+=2)if(crtptr[col]!='\x20')target=col;
  67.         for(col=0;col<=target;col+=2)fputc(crtptr[col],fp);
  68.         /* append the line with a cr-lf combination */
  69.         fputc('\x0d',fp);
  70.         fputc('\x0a',fp);
  71.         }
  72.  
  73.         fclose(fp);
  74.     }
  75.     enable();
  76. }
  77.  
  78. main()
  79. {
  80.     unsigned programsize;
  81.  
  82.     puts("Grabasc is now resident.");
  83.     puts("Use the Shift-Print-Screen Key Comination \
  84. to Capture Text Screens.");
  85.     puts("The Ascii Capture Buffer will be appended \
  86. to \"HANDFULL.TXT\".");
  87.     puts("Have a Nice Dos!");
  88.  
  89.     if ((biosequip() & 0x30) == 0x30)SCREENSEG=0xb000;
  90.     setvect(5,grabasc);
  91.     programsize=farsetsize(0);
  92.  
  93.     keep(0, programsize);
  94.  
  95. }
  96.